package xian.woniuxy.util;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
/**
 * @author haoxiufeng
 * @time 2021/12/01 16:12:00
 */
public class MybatisUtils {
    private static SqlSessionFactory sf;

    static {
        File file;
        try {
            InputStream in = new FileInputStream("src/main/resources/mybatis-config.xml");
            sf = new SqlSessionFactoryBuilder().build(in);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static SqlSession openSession() {
        return sf.openSession(true);
    }

}
